const path = require('path');
const merge = require('webpack-merge');
const HtmlWebPackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
// 引入基本配置
const baseWebpackConfig = require('./webpack.base.config.js');

module.exports = merge.smart(baseWebpackConfig, {
  // 打包模式
  mode: 'development', // 两个参数: production 和 development
  // sourceMap
  devtool: 'cheap-module-eval-source-map',
  module: {
    rules: [
      // 处理less
      {
        test: /\.less$/,
        use: ['style-loader', 'css-loader', 'less-loader']
      }
    ]
  },
  plugins: [
    // 自动将js引入HTML
    new HtmlWebPackPlugin({
      template: './index.html',
      filename: 'index.html',
      title: '2 Dome',
      favicon: 'favicon.ico',
      chunks: ['main']
    }),

    // 热更新
    new webpack.HotModuleReplacementPlugin()
  ],
  devServer: {
    port: '8080',
    contentBase: path.resolve(__dirname, '../public'),
    compress: true,
    // historyApiFallback: true,
    hot: true,
    inline: true,
    https: false,
    open: true
  }
});
